/*
 * Application.h
 *
 *  Created on: 2018年1月2日
 *      Author: chuanjiang.zh@qq.com
 */

#ifndef APPLICATION_H_
#define APPLICATION_H_

#include "BasicType.h"
#include "AppConfig.h"
#include <atomic>


class Application
{
public:
	static Application* instance();

	static void terminate();

public:
	Application();
	virtual ~Application();

	AppConfig& config();

	void setDaemon(bool isDaemon);
	
	int launch(int argc, char** argv);
	
	std::string getAppDir();

	std::string getName();

	virtual void exit() = 0;


protected:
	virtual void setupLog();

	virtual std::string getConfigPath();

	virtual std::string getLogFilePath();

	virtual bool initialize();

	virtual void uninitialize();

	virtual int run() = 0;

	virtual bool init();
	virtual void uninit();

protected:
	void setName(const std::string& name);
	void setDir(const std::string& dir);

protected:
	void setupSignal();

    void daemonize();

	bool checkResetInited();


protected:
	std::string	m_dir;
	std::string	m_name;
	bool	m_isDaemon;

    std::atomic_bool m_inited;

};

#endif /* APPLICATION_H_ */
